//流程控件,需要引用upStep.css

//下面为调用示例
// var param = {
//         currStep: 0,
//         width: 961,
//         isEditing: false,
//         callBack: function(newSteps) { //回调
//             debugger;
//         },
//         steps: [{
//             name: "提交订单",
//             describe: "说明您刚提交订单,还没有付款",
//             time: new Date()
//         }, {
//             name: "订单审核",
//             describe: "需要等待审核",
//             isDisAllowSrot: true,
//         }, {
//             name: "财务审核",
//             describe: "财务审核后才可以"
//         }, {
//             name: "出库审核"
//         }, {
//             name: "发货确认",
//             describe: "正在进行最后的确认"
//         }, {
//             name: "收获确认",
//             describe: "完成了"
//         }]
//     };
//     $scope.param = param;

commonApp.directive("upstep", function() {
    return {
        restrict: "ACE", // 指令是一个元素 (并非属性)
        scope: { // 设置指令对于的scope
            param: "=" // name 值传递 （字符串，单向绑定）
                //stepcount: "=", // name 值传递 （字符串，单向绑定）
                //amount: "=", // amount 引用传递（双向绑定）
                //theshow: "&" // 保存操作
        },
        templateUrl: $path$+"/public/template/upStepTemplate.html",
        replace: true,
        controller: function($scope, $element, $attrs, $transclude) {
            var upStepLogic = {
                showSort: function(index) {
                    if ($scope.param.isEditing) {
                        var currStep = $scope.param.steps[index];
                        if (!currStep.isDisAllowSrot) {
                            currStep.isShowSortDiv = true;
                        }
                    }
                },
                hideSort: function(index) {
                    if ($scope.param.isEditing) {
                        $scope.param.steps[index].isShowSortDiv = false;
                    }
                },
                toLeft: function(index) {
                    var oldIndex = index;
                    $scope.param.steps[index].isShowSortDiv = false;
                    index = --index;
                    if (index < 0) {
                        index = 0;
                    }
                    if ($scope.param.steps[index].isDisAllowSrot) {
                        index = oldIndex;
                        alert("固定项不可编辑");
                    }
                    var curr = $scope.param.steps.splice(oldIndex, 1);
                    $scope.param.steps.splice(index, 0, curr[0]);
                    $scope.param.callBack($scope.param.steps);
                },
                toRight: function(index) {
                    if (index == $scope.param.steps.length - 1) {
                        return false;
                    }
                    if ($scope.param.steps[index + 1].isDisAllowSrot) {
                        alert("固定项不可编辑");
                        return false;
                    }
                    $scope.param.steps[index].isShowSortDiv = false;
                    var curr = $scope.param.steps.splice(index, 1);
                    curr.isShowSortDiv = false;
                    $scope.param.steps.splice(index + 1, 0, curr[0]);
                    $scope.param.callBack($scope.param.steps);
                },
                setDebar: function(index) {
                    if ($scope.param.isEditing) {
                        var currStep = $scope.param.steps[index];
                        if (currStep.isDisAllowSrot) {
                            alert("固定项不可编辑");
                            return false;
                        }
                        currStep.isDebar = !currStep.isDebar;
                        $scope.param.callBack($scope.param.steps);
                    }
                }
            };
            $scope.upStepLogic = upStepLogic;
        }
    };
});
